ROOT_DIR = $(PWD)
LIB_DIR = $(ROOT_DIR)/lib
OBJ_DIR = $(ROOT_DIR)/obj
SRC_DIR = $(ROOT_DIR)/src
TARGET = $(ROOT_DIR)/bin/AiServer
TARGET_CROSS = $(ROOT_DIR)/bin/AiServer_aarch64
OBJS = $(subst /src,/obj,$(subst .cpp,.o,$(shell find $(SRC_DIR) -name "*.cpp")))

CXX := g++
LDFLAGS = -lsqlite3 -L$(LIB_DIR)/jsoncpp/lib -ljsoncpp -lpthread
CXXFLAGS = -Wall -O2 -std=c++11 -I$(LIB_DIR)/jsoncpp/include
AFTER_COMPILE := ./bin/AiServer

LINK_CAMMADN := make -C obj

ifeq ($(C), T)
	LIBJSONCPP = $(LIB_DIR)/jsoncpp/lib_cross
	LIBSQLITE = $(LIB_DIR)/sqlite3/lib
	CXX := aarch64-linux-gnu-g++
	LDFLAGS = -L$(LIBSQLITE) -lsqlite3 -L$(LIBJSONCPP) -ljsoncpp -lpthread
	CXXFLAGS = -Wall -O2 -std=c++11  -I$(LIB_DIR)/sqlite3/include -I$(LIB_DIR)/jsoncpp/include  -I$(LIB_DIR)/httplib
	AFTER_COMPILE = scp $(TARGET_CROSS) $(LIBJSONCPP)/libjsoncpp.so.27 $(LIBSQLITE)/libsqlite3.so linaro@192.168.21.78:/home/linaro/AiServer

	OBJ_DIR = $(ROOT_DIR)/obj/obj_cross
	OBJS = $(subst /src,/obj/obj_cross,$(subst .cpp,.o,$(shell find $(SRC_DIR) -name "*.cpp")))
	LINK_CAMMADN := make -C obj/obj_cross
endif

export CXX CXXFLAGS LDFLAGS OBJ_DIR OBJS TARGET TARGET_CROSS

all : src obj
	make -C src
	$(LINK_CAMMADN)
	@echo "---------------项目构建完成---------------"
	$(AFTER_COMPILE)

clean:
	rm -rf ./obj/*.o ./obj/obj_cross/*.o $(TARGET) $(TARGET_CROSS)
	@echo "---------------项目清理完成---------------"

cleanDb:
	rm ./database.db
	@echo "---------------数据库已重置---------------"
